//引入路由
import Router from 'vue-router'
import Vue from 'vue'

//将路由做为插件安装到vue上
Vue.use(Router)

const Login=()=>import("@/views/Login.vue")
const Main=()=>import("@/views/Main.vue")
const User=()=>import("@/views/sys/user/index.vue")
const Dict=()=>import("@/views/sys/dict/index.vue")
const Table=()=>import("@/views/sys/table/index.vue")


const routes=[
	//通过meta设置网页的标题栏
	{path:'/',name:"login",component:Login,meta:{title:"登录"}},
	
	{path:'/main',name:"main",component:Main,meta:{title:"主页面"},
	//嵌套路由，(子路由)
	children:[
		{path:'/user',name:"user",component:User,meta:{title:"用户管理"}},
		//  /user 是这个路由 http://localhost:8080/user
		{path:'/dict',name:"dict",component:Dict,meta:{title:"词典管理"}},
		{path:'/table',name:"table",component:Table,meta:{title:"表格数据"}}
	]
	}
	
]

//创建路由
var router=new Router({
	routes,
	//mode:"history" //路由模式 设置完之后 访问路径里面没有#了
});

//配置全局路由前置守卫
//判断用户是否登录  判断用户是否有权限
router.beforeEach((to,from,next)=>{
	console.log("to>>>>",to),
	//更改组件标题
	document.title=to.meta.title
	next()
})
export default router